<?

/***************************************************************************
 Jupiter Content System @ Jupiterportal.com
 Copyright (C) 2005 Cosmin Flavius (highstrike@gmail.com)

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 More Info About The Licence At http://www.gnu.org/copyleft/gpl.html
****************************************************************************/

//-----------------------------------------------------------------
//  Filter Acces Rightes
//-----------------------------------------------------------------

if(!isset($is_webmaster))
{ header("location: $PHP_SELF?i=2"); exit; }

switch($a)
{
	//-----------------------------------------------------------------
	//  Save CFG
	//-----------------------------------------------------------------

	case 1:

		//-----------------------------------------------------------------
		//  BBcode check
		//-----------------------------------------------------------------

		for ($i = 1; $i <= 5; $i++)
		{
			if(check_tag_order($edit_terms_txt) == $i) { header("location: $PHP_SELF?n=modules/system&i=9$i"); exit; }
			if(check_tag_order($edit_maintance_message) == $i) { header("location: $PHP_SELF?n=modules/system&i=9$i"); exit; }
			if(check_tag_order($edit_ban_message) == $i) { header("location: $PHP_SELF?n=modules/system&i=9$i"); exit; }
		}

		//-----------------------------------------------------------------
		//  Take care of some things
		//-----------------------------------------------------------------

		$edit_terms_txt = jcm_linebreaks(trim(jcm_stripslashes($edit_terms_txt)));
		$edit_maintance_message = jcm_linebreaks(trim(jcm_stripslashes($edit_maintance_message)));
		$edit_ban_message = jcm_linebreaks(trim(jcm_stripslashes($edit_ban_message)));
		if($overflow = check_tag_order($edit_terms_txt)) $edit_terms_txt = substr($edit_terms_txt, 0, $overflow[0]).substr($edit_terms_txt, $overflow[1], (strlen($edit_terms_txt) - $overflow[0]));
		if($overflow = check_tag_order($edit_maintance_message)) $edit_maintance_message = substr($edit_maintance_message, 0, $overflow[0]).substr($edit_maintance_message, $overflow[1], (strlen($edit_maintance_message) - $overflow[0]));
		if($overflow = check_tag_order($edit_ban_message)) $edit_ban_message = substr($edit_ban_message, 0, $overflow[0]).substr($edit_ban_message, $overflow[1], (strlen($edit_ban_message) - $overflow[0]));

		//-----------------------------------------------------------------
		//   Write the new cfg in the table
		//-----------------------------------------------------------------

		$cfg['website_name'] = $edit_website_name;
		$cfg['webmaster_name'] = $edit_webmaster_name;
		$cfg['webmaster_email'] = $edit_webmaster_email;
		$cfg['template'] = $edit_template;
		$cfg['language'] = $edit_language;
		$cfg['bbcode'] = $edit_bbcode;
		$cfg['emoticons'] = $edit_emoticons;
		$cfg['badwords'] = $edit_badwords;
		$cfg['badword_mode'] = $edit_badword_mode;
		$cfg['avatar_size'] = $edit_avatar_size;
		$cfg['verify_reg'] = $edit_verify_reg;
		$cfg['terms_tg'] = $edit_terms_tg;
		$cfg['terms_txt'] = $edit_terms_txt;
		$cfg['inbox_msg'] = $edit_inbox_msg;
		$cfg['sentbox_msg'] = $edit_sentbox_msg;
		$cfg['forum_name'] = $edit_forum_name;
		$cfg['forum_hot'] = $edit_forum_hot;
		$cfg['forum_guest_see'] = $edit_forum_guest_see;
		$cfg['forum_guest_topic'] = $edit_forum_guest_topic;
		$cfg['forum_guest_reply'] = $edit_forum_guest_reply;
		$cfg['nav_news'] = $edit_nav_news;
		$cfg['nav_log'] = $edit_nav_log;
		$cfg['nav_users'] = $edit_nav_users;
		$cfg['nav_bans'] = $edit_nav_bans;
		$cfg['nav_pm'] = $edit_nav_pm;
		$cfg['nav_topics'] = $edit_nav_topics;
		$cfg['nav_replies'] = $edit_nav_replies;
		$cfg['maintance'] = $edit_maintance;
		$cfg['maintance_message'] = $edit_maintance_message;
		$cfg['ban_message'] = $edit_ban_message;

		while (list($key, $input) = @each($cfg)) if ($config[$key] != $input) $db->updateRow("config",array('value' => ''.$input.''),"variable = '$key'");

		//-----------------------------------------------------------------
		//  Redirect when finished
		//-----------------------------------------------------------------

		header("location: $PHP_SELF?n=modules/system&i=56");

	break;

	//-----------------------------------------------------------------
	//  Show list + form
	//-----------------------------------------------------------------

	default:

		//-----------------------------------------------------------------
		// Echo the back link
		//-----------------------------------------------------------------

		echo "<table class='main' cellspacing='1' cellpadding='4'><tr class='head'><td colspan='3'>{$language['Admin name']}</td></tr><tr><td colspan='3' class='con1' onMouseOver=this.className='con3' onMouseOut=this.className='con1' onclick=window.location.href='$PHP_SELF?n=modules/admin'><a href='$PHP_SELF?n=modules/admin'> &raquo; {$language['Admin back']}</a></td></tr></table><br>";

		//-----------------------------------------------------------------
		//  Load dropdown_form for templates directory
		//-----------------------------------------------------------------

		$array_template = array();
		$dir_template = opendir( './templates' );

		while ($file_template = readdir($dir_template))
			if(!preg_match( "/^..?$|^index|htm$|html$|^\./i", $file_template))
				$array_template[] = array($file_template, $file_template);

		closedir($dir_template);
		sort($array_template);
		reset($array_template);

		//-----------------------------------------------------------------
		//  Load dropdown_form for lang files
		//-----------------------------------------------------------------
        
        $language_db = $db->getTable("SELECT id, name FROM languages WHERE ".
                                     "active = 1");
		$array_language = array();
        
        foreach ($language_db as $lng)
        {
            if (isset($language['Language '.$lng['id']]))
                $lname = $language['Language '.$lng['id']];
            else $lname = $lng['name'];
            $array_language[] = array($lng['id'], $lname);
        } ?>
			<form method="post" action="<?= $PHP_SELF ?>?n=modules/system">
			<table class="main" cellspacing="1" cellpadding="4" width="100%">
			<tr class="head"> 
			<td colspan="2" class="head"><?= $language['System main title'] ?></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System general title'] ?></td>
			</tr>
			<tr>
			<td class="con1" width="42%"><?= $language['System general desc'] ?></td>
			<td class="con1" width="58%"><input type="text" value="<?= $config['website_name'] ?>" name="edit_website_name" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System general desc2'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['webmaster_name'] ?>" name="edit_webmaster_name" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System general desc3'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['webmaster_email'] ?>" name="edit_webmaster_email" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System general desc4'] ?></td>
			<td class="con1"><?= form_dropdown('edit_template', $array_template, $config['template'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System general desc5'] ?></td>
			<td class="con1"><?= form_dropdown('edit_language', $array_language, $config['language'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System parse title'] ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System parse desc'] ?></td>
			<td class="con1"><?= form_dropdown('edit_bbcode', Array('0' => Array('0' => '0','1' => ''.$language['Disabled'].''),'1' => Array('0' => '1','1' => ''.$language['Enabled'].'')), $config['bbcode'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System parse desc2'] ?></td>
			<td class="con1"><?= form_dropdown('edit_emoticons', Array('0' => Array('0' => '0','1' => ''.$language['Disabled'].''),'1' => Array('0' => '1','1' => ''.$language['Enabled'].'')), $config['emoticons'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System parse desc3'] ?></td>
			<td class="con1"><?= form_dropdown('edit_badwords', Array('0' => Array('0' => '0','1' => ''.$language['Disabled'].''),'1' => Array('0' => '1','1' => ''.$language['Enabled'].'')), $config['badwords'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System parse desc4'] ?></td>
			<td class="con1"><?= form_dropdown('edit_badword_mode', Array('0' => Array('0' => '0','1' => ''.$language['System parse desc5'].''),'1' => Array('0' => '1','1' => ''.$language['System parse desc6'].'')), $config['badword_mode'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System register title'] ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System register desc'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['avatar_size'] ?>" name="edit_avatar_size" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System register desc2'] ?></td>
			<td class="con1"><?= form_dropdown('edit_verify_reg', Array('0' => Array('0' => '0','1' => ''.$language['Register desc15'].''),'1' => Array('0' => '1','1' => ''.$language['Register desc14'].'')), $config['verify_reg'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System register desc3'] ?></td>
			<td class="con1"><?= form_dropdown('edit_terms_tg', Array('0' => Array('0' => '0','1' => ''.$language['Register desc15'].''),'1' => Array('0' => '1','1' => ''.$language['Register desc14'].'')), $config['terms_tg'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1" valign="top"><?= "{$language['System register desc4']}".dis_bb_em()."" ?></td>
			<td class="con1"><textarea style="width:100%; height:70px;" class="box" name="edit_terms_txt"><?= $config['terms_txt'] ?></textarea></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System pm title'] ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System pm desc'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['inbox_msg'] ?>" name="edit_inbox_msg" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System pm desc2'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['sentbox_msg'] ?>" name="edit_sentbox_msg" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System forum title'] ?></td>
			</tr>
			<tr>
			<td class="con1" width="42%"><?= $language['System forum desc'] ?></td>
			<td class="con1" width="58%"><input type="text" value="<?= $config['forum_name'] ?>" name="edit_forum_name" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System forum desc2'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['forum_hot'] ?>" name="edit_forum_hot" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1" width="42%"><?= $language['System forum desc3'] ?></td>
			<td class="con1"><?= form_dropdown('edit_forum_guest_see', Array('0' => Array('0' => '0','1' => ''.$language['Register desc15'].''),'1' => Array('0' => '1','1' => ''.$language['Register desc14'].'')), $config['forum_guest_see'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1" width="42%"><?= $language['System forum desc4'] ?></td>
			<td class="con1"><?= form_dropdown('edit_forum_guest_topic', Array('0' => Array('0' => '0','1' => ''.$language['Register desc15'].''),'1' => Array('0' => '1','1' => ''.$language['Register desc14'].'')), $config['forum_guest_topic'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1" width="42%"><?= $language['System forum desc5'] ?></td>
			<td class="con1"><?= form_dropdown('edit_forum_guest_reply', Array('0' => Array('0' => '0','1' => ''.$language['Register desc15'].''),'1' => Array('0' => '1','1' => ''.$language['Register desc14'].'')), $config['forum_guest_reply'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System items title'] ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_news'] ?>" name="edit_nav_news" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc2'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_log'] ?>" name="edit_nav_log" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc3'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_users'] ?>" name="edit_nav_users" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc4'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_bans'] ?>" name="edit_nav_bans" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc5'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_pm'] ?>" name="edit_nav_pm" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc6'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_topics'] ?>" name="edit_nav_topics" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System items desc7'] ?></td>
			<td class="con1"><input type="text" value="<?= $config['nav_replies'] ?>" name="edit_nav_replies" style="width:100%" maxlength="25" class="box"></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System maintenace title'] ?></td>
			</tr>
			<tr>
			<td class="con1"><?= $language['System maintenace desc'] ?></td>
			<td class="con1"><?= form_dropdown('edit_maintance', Array('0' => Array('0' => '0','1' => ''.$language['Disabled'].''),'1' => Array('0' => '1','1' => ''.$language['Enabled'].'')), $config['maintance'], "style='width:100%'", "class='box'", "") ?></td>
			</tr>
			<tr>
			<td class="con1" valign="top"><?= "{$language['System maintenace desc2']}".dis_bb_em()."" ?></td>
			<td class="con1"><textarea style="width:100%; height:70px;" class="box" name="edit_maintance_message"><?= $config['maintance_message'] ?></textarea></td>
			</tr>
			<tr>
			<td class="con1" valign="top"><?= "{$language['System maintenace desc3']}".dis_bb_em()."" ?></td>
			<td class="con1"><textarea style="width:100%; height:70px;" class="box" name="edit_ban_message"><?= $config['ban_message'] ?></textarea></td>
			</tr>
			<tr class="bottom"> 
			<td colspan="2"><?= $language['System action title'] ?></td>
			</tr>
			<tr>
			<td class="con1"><input type="button" style="width:100" class="box" value="<?= $language['System action desc'] ?>" onClick="window.history.go(-1);"></td>
			<td class="con1" align="right"><input type="submit" style="width:100" class="box" value="<?= $language['System action desc2'] ?>"></td>
			</tr>
			<input type="hidden" name="a" value="1">
			</table></form>
		<?
}
?>